<?
include "../db_config.php";
echo "{\"totalNum\":";
$b1 = $HTTP_GET_VARS['b1'];
$b2 = $HTTP_GET_VARS['b2'];
$b3 = $HTTP_GET_VARS['b3'];
$b4 = $HTTP_GET_VARS['b4'];
$sourceNum = $HTTP_GET_VARS['sourceNum'];


$totalNum = '0';
$condition = "latitude >= $b3 and latitude <= $b1 and longitude >= $b2 and longitude <= $b4";

if($sourceNum != null)
{
	$condition .= " and sourceNum >= $sourceNum";
}
$sql = "select COUNT(*) from wps_ap_info where $condition";
$result = mysql_query($sql);
if($data = mysql_fetch_array($result))
	$totalNum = $data['COUNT(*)'];

//limit max num of AP
$maxAPNum = 100;
if($totalNum > $maxAPNum)
	$totalNum = "'$maxAPNum+'";

echo $totalNum . ",\"Points\":[";

$sql = "select *, COUNT(*) from wps_ap_info 
where $condition group by pos
limit $maxAPNum";
//$sql = "select * from wps_ap_info where $condition";
$result = mysql_query($sql);
$i = 0;
$del = "";
while($data = mysql_fetch_array($result))
{
	$sql2 = "select * from wps_ap_info where pos = '".$data['pos']."'";
	//$sql2 = "select * from wps_ap_info where bssid = '".$data[bssid]."'";
	$r = mysql_query($sql2);
	$ssids = "";
	while($d = mysql_fetch_array($r))
	{
		$bssid = $d[bssid];
		/*
		$sql2 = "select COUNT(*) from ap_raw_data where bssid like '$bssid'";
		$r2 = mysql_query($sql2);
		$d2 = mysql_fetch_array($r2);
		$ap_log_no = $d2['COUNT(*)'];
		*/
		$ap_log_no = $d[sourceNum];
		if($d[ssid] == "")
			$ssids .= "hidden";
		else
			$ssids .= ($d[ssid]);
		$ssids .= "($bssid)";//');\\\">$bssid</a><BR>";
		$ssids .= " <a href=\\\"javascript:getAPRawData('$bssid');\\\">show $ap_log_no logs</a><BR>";
	}
	$lat = $data['latitude'];
	$lng = $data['longitude'];
	$snr = $data['ssid'];
	$no = $data['COUNT(*)'];
	//$no = 1;
	echo $del;
	echo "{\"lat\":$lat,\"lng\":$lng,\"no\":$no,\"lists\":\"$ssids\"}";
	if($del == "")
		$del = ", ";
	//echo "addmarker($lat, $lng, $no, '$ssids');\n"; 
	$i++;
}
echo "]}";

?>

